Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore "package.json" as config file when it's invalid JSON #1281

Merged
merged 1 commit into from
Apr 7, 2023

Conversation

iiroj
Copy link
Member

@iiroj iiroj commented Apr 7, 2023

This PR hides the JSON parser error when trying to load lint-staged config from an invalid package.json file:

% node bin/lint-staged.js
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at jsonParse (file:///Users/iiro/git/lint-staged/lib/loadConfig.js:30:43)
    at Object.load (/Users/iiro/git/lint-staged/node_modules/lilconfig/dist/index.js:148:35)
    at async loadConfig (file:///Users/iiro/git/lint-staged/lib/loadConfig.js:65:20)
    at async Promise.all (index 1)
    at async searchConfigs (file:///Users/iiro/git/lint-staged/lib/searchConfigs.js:84:3)
    at async runAll (file:///Users/iiro/git/lint-staged/lib/runAll.js:129:24)
    at async lintStaged (file:///Users/iiro/git/lint-staged/lib/index.js:108:17)
✔ Preparing lint-staged...
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Cleaning up temporary files...

Instead a debug log entry will be emitted (in this case an empty file):

  lint-staged:loadConfig Ignoring invalid package file `/Users/iiro/git/lint-staged/test/package.json` with content:
  lint-staged:loadConfig  +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/iiro/git/lint-staged/test/package.json`:
  lint-staged:loadConfig null +0ms

@iiroj iiroj requested a review from okonet April 7, 2023 07:19
@codecov
Copy link

codecov bot commented Apr 7, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (05fb382) 100.00% compared to head (1b51eec) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1281   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          733       740    +7     
  Branches       197       198    +1     
=========================================
+ Hits           733       740    +7     
Impacted Files Coverage Δ
lib/loadConfig.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@iiroj iiroj merged commit e7ed6f7 into master Apr 7, 2023
@iiroj iiroj deleted the fix/ignore-invalid-package-file branch April 7, 2023 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

SyntaxError: Unexpected token } in JSON at position 199 at JSON.parse() Loading too many package.json files
2 participants